package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysDictType;
import io.mybatis.example.springboot.service.SysDictTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_dict_type - 字典类型表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysDictTypes")
public class SysDictTypeController {

  @Autowired
  private SysDictTypeService sysDictTypeService;

  @PostMapping
  public DataResponse<SysDictTypeDO> save(@RequestBody SysDictTypeDO sysDictType) {
    return DataResponse.ok(sysDictTypeService.save( sysDictType));
  }

  @GetMapping
  public RowsResponse<SysDictTypeDO> findList(@RequestBody SysDictTypeDO sysDictType) {
    return RowsResponse.ok(sysDictTypeService.findList( sysDictType));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysDictTypeDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysDictTypeService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysDictTypeDO> update(@PathVariable("id") Long id, @RequestBody SysDictTypeDO sysDictType) {
    sysDictType.setId(id);
    return DataResponse.ok(sysDictTypeService.update( sysDictType));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysDictTypeService.deleteById(id) == 1);
  }

}
